package com.slipper.system.codeless.controller;

import com.slipper.system.codeless.bo.ViewBO;
import com.slipper.system.codeless.service.TableService;
import com.slipper.util.*;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 库表信息表
 */
@RestController
@RequestMapping("/system/table")
public class TableController {
    @Resource
    private TableService tableService;

    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody ViewBO bo) {
        return ResultUtil.successResult(tableService.queryPage(bo));
    }

    @PostMapping(value = "/queryColumn")
    public String queryColumn(@RequestBody ViewBO bo) {
        if (Tool.isBlank(bo.getName())) {
            return ResultUtil.failureResult("源表参数不正确！");
        }

        return ResultUtil.successResult(tableService.queryColumn(bo));
    }

    @PostMapping(value = "/queryIndex")
    public String queryIndex(@RequestBody ViewBO bo) {
        if (Tool.isBlank(bo.getName())) {
            return ResultUtil.failureResult("源表参数不正确！");
        }

        return ResultUtil.successResult(tableService.queryIndex(bo));
    }
}